package com.aspose.cells;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;

class zol {
   Worksheet a;
   Workbook b;
   int c;
   int d;
   zok e;
   ArrayList f;
   String g;
   ArrayList h;
   int i = 0;
   private ArrayList z;
   HashMap j = new HashMap();
   String k = null;
   zog l = new zog();
   znx m = null;
   zog n = null;
   ArrayList o = new ArrayList();
   ArrayList p = new ArrayList();
   String q;
   String r;
   String s;
   HashMap t = new HashMap();
   ArrayList u = new ArrayList();
   HashMap v = new HashMap();
   HashMap w = new HashMap();
   String x = null;
   HashMap y;

   zol(zok var1, Worksheet var2, int var3, int var4) throws Exception {
      this.e = var1;
      this.b = var1.a;
      this.a = var2;
      boolean var5 = ".bin".equals(this.e.p);
      this.c = var3;
      this.d = var4;
      this.h = new ArrayList();
      this.z = new ArrayList();
      this.j();
      this.m();
      this.f();
      this.a();
      this.a(var5);
      this.k();
      this.g();
      this.l();
      this.e();
      this.b(var5);
      if (this.a.getType() == 1) {
         this.d();
      }

      this.h();
      this.i();
   }

   void a() throws Exception {
      ShapeCollection var1 = this.a.t();
      if (var1 != null && var1.getCount() > 0) {
         for(int var2 = 0; var2 < var1.getCount(); ++var2) {
            Shape var3 = var1.get(var2);
            zpf var4 = var3.x;
            if (var4 != null) {
               if (var4.a()) {
                  if (!this.p.contains(var4) && this.e.q) {
                     var4.h = this.a(var4.g, var4.c).c;
                     com.aspose.cells.b.a.a.ze.a(this.p, (Object)var4);
                  }
               } else {
                  if (var3.getMsoDrawingType() == 8) {
                     Picture var5 = (Picture)var3;
                     String var6 = "../media/" + (String)this.e.f.get(var5.b());
                     var4.f = this.b("http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", var6, (String)null);
                  }

                  if (!this.p.contains(var4)) {
                     if (var4.i == null) {
                        zab.a(var4, var4.k, this.e.a);
                     }

                     if (var4.i != null) {
                        boolean var10 = true;
                        int var11 = 0;
                        com.aspose.cells.b.a.a.ze.a(this.p, (Object)var4);
                        if (var4.i.getType() == 11) {
                           UnknownControl var7 = (UnknownControl)var4.i;
                           var10 = var7.g == 3;
                           if (var7.h != null) {
                              var11 = var7.h.size();
                           }
                        }

                        if (var10) {
                           var11 = 1;
                        }

                        var4.j = this.e.x;
                        this.e.a(false, "/xl/activeX/activeX" + var4.j + ".xml", "application/vnd.ms-office.activeX+xml");
                        String var12 = "../activeX/activeX" + var4.j + ".xml";
                        String var8 = this.a("http://schemas.openxmlformats.org/officeDocument/2006/relationships/control", var12).c;
                        var4.h = var8;
                        if (var11 > 0) {
                           if (this.e.B == null) {
                              znt var9 = this.e.a(true, "bin", "application/vnd.ms-office.activeX");
                              this.e.B = var9.d;
                           }

                           if (!"application/vnd.ms-office.activeX".equals(this.e.B)) {
                              for(int var13 = 0; var13 < var11; ++var13) {
                                 var12 = "/xl/activeX/activeX" + (var4.j + var13) + ".bin";
                                 this.e.a(false, var12, "application/vnd.ms-office.activeX");
                              }
                           }
                        }

                        this.e.x += var11 == 0 ? 1 : var11;
                     }
                  }
               }
            }
         }

      }
   }

   void a(boolean var1) {
      String var2 = var1 ? "application/vnd.ms-excel.table" : "application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml";
      ListObjectCollection var3 = this.a.j();
      if (var3 != null) {
         for(int var4 = 0; var4 < var3.getCount(); ++var4) {
            ListObject var5 = var3.get(var4);
            if (var5.b == null || var5.b.length <= 0) {
               String var6 = "/tables/table" + this.e.f() + this.e.p;
               String var7 = this.a("http://schemas.openxmlformats.org/officeDocument/2006/relationships/table", ".." + var6).c;
               this.e.a("/xl" + var6, var2);
               this.v.put(var5, var7);
            }
         }
      }

      if (this.a.g != null && this.a.g.h != null) {
         String var8 = "/tables/tableSingleCells" + this.e.g() + this.e.p;
         this.a("http://schemas.openxmlformats.org/officeDocument/2006/relationships/tableSingleCells", ".." + var8);
         this.x = "xl" + var8;
         this.e.a("/xl" + var8, "application/vnd.openxmlformats-officedocument.spreadsheetml.tableSingleCells+xml");
      }

   }

   void b() throws Exception {
      if (this.b.b != null) {
         if (this.a.t() != null) {
            this.b.b.a((Collection)this.a.t().a());
         }

         for(int var1 = 0; var1 < this.a.getCharts().getCount(); ++var1) {
            Chart var2 = this.a.getCharts().get(var1);
            if (var2.l() != null) {
               this.b.b.a((Collection)var2.l().a());
            }
         }

         if (this.a.g != null) {
            this.b.b.a((Collection)this.a.g.q);
         }

      }
   }

   private void d() throws Exception {
      if (this.a.B() != null) {
         int var1 = this.a.B().getCount();

         for(int var2 = 0; var2 < var1; ++var2) {
            CustomProperty var3 = this.a.getCustomProperties().get(var2);
            zoe var4 = new zoe();
            var4.a = var3.getName();
            var4.c = "customProperty" + this.e.e() + ".bin";
            var4.b = this.a("http://schemas.openxmlformats.org/officeDocument/2006/relationships/customProperty", "../" + var4.c).c;
            var4.d = Encoding.getUnicode().a(var3.getValue());
            com.aspose.cells.b.a.a.ze.a(this.u, (Object)var4);
            znt var5 = new znt();
            var5.d = "application/vnd.openxmlformats-officedocument.spreadsheetml.customProperty";
            var5.c = "/xl/" + var4.c;
            com.aspose.cells.b.a.a.ze.a(this.e.o, (Object)var5);
         }

      }
   }

   private void e() throws Exception {
      byte[] var1 = this.a.getBackgroundImage();
      if (var1 != null) {
         int var2 = com.aspose.cells.a.d.zbn.a(var1);
         int var3 = this.e.d();
         if (var2 == 6) {
            this.q = "image" + var3 + ".png";
         } else {
            this.q = zase.a("image", var3, var2);
         }

         this.r = this.a("http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", "../media/" + this.q).c;
      }
   }

   private void a(byte[] var1, znb var2, boolean var3) {
      if (var1 != null && var1.length > 0) {
         String var4 = "/printerSettings/printerSettings" + this.e.v++ + ".bin";
         String var5 = this.a("http://schemas.openxmlformats.org/officeDocument/2006/relationships/printerSettings", ".." + var4).c;
         if (var2 != null) {
            var2.b = var5;
         } else {
            this.s = var5;
         }

         this.t.put("xl" + var4, var1);
         if (var3) {
            this.e.a(false, "/xl" + var4, "application/vnd.openxmlformats-officedocument.spreadsheetml.printerSettings");
         } else {
            if (this.e.B == null) {
               znt var6 = this.e.a(true, "bin", "application/vnd.openxmlformats-officedocument.spreadsheetml.printerSettings");
               this.e.B = var6.d;
            }

            if (!"application/vnd.openxmlformats-officedocument.spreadsheetml.printerSettings".equals(this.e.B)) {
               this.e.a(false, "/xl" + var4, "application/vnd.openxmlformats-officedocument.spreadsheetml.printerSettings");
            }
         }
      }

   }

   private void b(boolean var1) {
      byte[] var2 = this.a.getType() == 2 ? this.a.getCharts().get(0).getPageSetup().a() : this.a.getPageSetup().a();
      this.a(var2, (znb)null, var1);
      if (this.a.n != null && this.a.n.getCount() != 0) {
         for(int var3 = 0; var3 < this.a.n.getCount(); ++var3) {
            var2 = this.a.n.a(var3).e().a();
            this.a(var2, this.a.n.a(var3), var1);
         }
      }

   }

   private void f() {
      if (this.c()) {
         this.g = "comments" + zase.y(this.c) + this.e.p;
         this.a("http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments", "../" + this.g);
      }

   }

   private void g() throws Exception {
      this.n = new zog(this);
   }

   private void h() {
      if (this.a.b != null && this.a.b.getCount() != 0) {
         for(int var1 = 0; var1 < this.a.b.getCount(); ++var1) {
            PivotTable var2 = this.a.b.get(var1);
            int var3 = (Integer)this.e.i.get(var2);
            String var4 = this.e.q ? ".xml" : ".bin";
            String var5 = "../pivotTables/pivotTable" + var3 + var4;
            this.a("http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotTable", var5);
         }

      }
   }

   private void i() {
      if (0 != this.a.d().getCount()) {
         this.y = new HashMap();
         Iterator var1 = this.a.d().iterator();

         while(var1.hasNext()) {
            zbmt var2 = (zbmt)var1.next();
            if (this.y.get(var2.a) == null) {
               String var3 = "../slicers/slicer" + this.e.j + this.e.p;
               zqe var4 = this.a("http://schemas.microsoft.com/office/2007/relationships/slicer", var3);
               this.y.put(var2.a, var4);
               String var5 = "/xl/slicers/slicer" + this.e.j + this.e.p;
               this.e.a(var5, "application/vnd.ms-excel.slicer+xml");
               ++this.e.j;
            }
         }

      }
   }

   private void j() {
      if (this.a.g != null) {
         ArrayList var1 = this.a.g.j;

         int var2;
         for(var2 = 0; var2 < var1.size(); ++var2) {
            zqe var3 = (zqe)var1.get(var2);
            var3.b = var3.c;
            this.a(var3.c, var3.d, var3.e);
         }

         var1 = this.p;

         for(var2 = 0; var2 < var1.size(); ++var2) {
            zpf var7 = (zpf)var1.get(var2);
            boolean var4 = false;
            Iterator var5 = this.h.iterator();

            while(var5.hasNext()) {
               zqe var6 = (zqe)var5.next();
               if (com.aspose.cells.b.a.zv.b(var6.e, var7.c)) {
                  var7.h = var6.c;
                  var4 = true;
                  break;
               }
            }

            if (!var4) {
               var7.h = this.a("http://schemas.openxmlformats.org/officeDocument/2006/relationships/control", var7.c).c;
            }
         }

      }
   }

   private void k() {
      this.m = new znx(this);
      if (this.m.b != null) {
         this.m.a = this.a("http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing", "../drawings/" + this.m.b).c;
      }

   }

   private void l() {
      if (this.e.g != null && this.e.g.size() != 0) {
         this.l = new zog();
         ShapeCollection var1 = this.a.getPageSetup().j();
         if (var1 != null && var1.getCount() != 0) {
            Iterator var2 = var1.iterator();

            while(var2.hasNext()) {
               Shape var3 = (Shape)var2.next();
               Picture var4 = (Picture)var3;
               if (this.e.g.containsKey(var4.b()) && !this.l.d.containsKey(var4.b())) {
                  String var5 = "../media/" + (String)this.e.g.get(var4.b());
                  String var6 = this.l.a("http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", var5);
                  this.l.d.put(var4.b(), var6);
               }
            }

            if (this.l.c.size() == 0) {
               this.l = new zog();
            } else {
               this.l.b = "vmlDrawing" + zase.y(this.e.a()) + ".vml";
               String var7 = "../drawings/" + this.l.b;
               this.l.a = this.a("http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing", var7).c;
            }

         }
      }
   }

   boolean c() {
      return this.a.getComments() != null && this.a.getComments().getCount() > 0;
   }

   private void m() {
      if (this.a.getHyperlinks() != null && this.a.getHyperlinks().getCount() >= 1) {
         int var1 = this.a.getHyperlinks().getCount();
         this.f = new ArrayList(var1);

         for(int var2 = 0; var2 < var1; ++var2) {
            Hyperlink var3 = this.a.getHyperlinks().get(var2);
            zoa var4 = new zoa();
            var4.b = var3;
            var4.c = var3.getAddress();
            var4.d = var3.a(this.b.getWorksheets());
            if (var4.d != 0 && var4.d != 1) {
               if (var4.d == 2) {
                  int var7 = var4.c.indexOf(35);
                  if (var7 != -1) {
                     String var6 = var4.c.substring(0, 0 + var7);
                     var4.a = this.b("http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", var6, "External");
                     var4.c = var4.c.substring(var7 + 1);
                  }
               }
            } else {
               String var5 = zbue.a(var3.getAddress());
               if (var4.d == 1 && var5.indexOf(":") != -1) {
                  var5 = "file:///" + var5;
               }

               var4.a = this.b("http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", var5, "External");
            }

            com.aspose.cells.b.a.a.ze.a(this.f, (Object)var4);
         }

      }
   }

   void a(String var1, String var2, String var3) {
      int var4 = com.aspose.cells.b.a.zo.a(var1.substring(3, 3 + (var1.length() - 3)));
      com.aspose.cells.b.a.a.ze.a(this.z, (Object)var4);
      zqe var5 = new zqe(var1, var2, var3, (String)null);
      com.aspose.cells.b.a.a.ze.a(this.h, (Object)var5);
   }

   zqe a(String var1, String var2) {
      String var3 = "rId" + this.n();
      zqe var4 = new zqe(var3, var1, var2, (String)null);
      com.aspose.cells.b.a.a.ze.a(this.h, (Object)var4);
      return var4;
   }

   private String b(String var1, String var2, String var3) {
      String var4 = "rId" + this.n();
      zqe var5 = new zqe(var4, var1, var2, var3);
      com.aspose.cells.b.a.a.ze.a(this.h, (Object)var5);
      return var4;
   }

   private int n() {
      int var1;
      for(var1 = ++this.i; this.z.contains(var1); var1 = ++this.i) {
         ;
      }

      return var1;
   }
}
